import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { EnumLocalStorageKey } from '@/enums/localStorage'
import { ElMessage } from 'element-plus'

type localeValue = 'zh-CN' | 'en-US'

const LOCALE_OPTIONS = [
  { label: '中文', value: 'zh-CN' },
  { label: 'English', value: 'en-US' }
]

export default function useLocale() {
  const i18 = useI18n()
  const currentLocale = computed(() => {
    return i18.locale.value
  })
  const changeLocale = (value: localeValue) => {
    i18.locale.value = value
    localStorage.setItem(EnumLocalStorageKey.CampusAdminLocale, value)
    ElMessage({
      showClose: true,
      type: 'success',
      message: `${i18.t('settings.topNavbar.action.locale')}`,
      duration: 800
    })
  }
  return {
    currentLocale,
    changeLocale,
    LOCALE_OPTIONS
  }
}
